<template>
<div class="abc">
    <el-row>
        <div>
            <el-button type="info" @click="pushPermissions">角色</el-button>
            <el-button type="info">修改角色</el-button>
        </div>
        <div>
            <div class="zhanghao1 clear">
               <h4>
                    角色名称:
                </h4>
                <div>
                    <el-input
                        placeholder="请输入角色"
                        v-model="role_name"
                        clearable>
                    </el-input>
                </div>
            </div>
        </div>
        <div>
            <el-tabs v-model="activeName">
                <el-tab-pane label="权限" name="first">
                    <el-tree
                    :data="data"
                    show-checkbox
                    default-expand-all
                    node-key="auth_id"
                    ref="tree"
                    highlight-current
                    :props="defaultProps">
                    </el-tree>
                </el-tab-pane>
            </el-tabs>
        </div>
        <div class="annui">
            <el-button type="primary" @click="savesubmit()">保存</el-button>
        </div>
    </el-row>
</div>
   
</template>

<script>
export default {
    name:'Department',
    data() {
        return {
            //角色名称
            role_name:'' ,
            //页面跳转
            activeName: 'first',
            //树状图数据
            data: [{
                auth_name: '',
                authorityList: [{
                    auth_name: '',
                }]
                }],
                defaultProps: {
                children: 'authorityList',
                label: 'auth_name',
                }
            }
    },
    methods: {
        pushPermissions(){
          this.$router.push({
               name:'权限设置',
               path:'/Home/Homemin/Permissions',
               query: {

                    },
          })
        },
        handleClick(tab, event){
            // console.log(tab, event);
        },
        addRoleQiangxiang(){
            this.axios({
            method:'get',
            url:'http://172.16.10.70:8080/authority/findAuthority',
        }).then((data)=>{
            this.data =data.data.data
        })   
        },
        savesubmit(){
            let arr=this.$refs.tree.getCheckedKeys();
            let obj=[]
            arr.forEach(item=>{
                obj.push({auth_id:item})
            })
            this.axios({
            method:'post',
            url:'http://172.16.10.84:8080/role/addRole',
            data:{
                role_name: this.role_name,
                authorityList:obj
            }
        }).then((data)=>{           
           console.log(data);
            this.$router.push({
               name:'权限设置',
               path:'/Home/Homemin/Permissions',
               query: {

                    },
          })
        })  
        obj=[]
        },
    },
    created(){
       this.addRoleQiangxiang()
    },
}
</script>

<style lang='less' scoped>
.abc{
    width: 98%;
    margin: 0 auto;
    margin-top: 15px;
    margin-left: 15px;
}
.zhanghao1{
    margin: 2%;
}
.zhanghao1 h4{
    float: left;
    height: 40px;
    line-height: 40px;
}
.zhanghao1 div{
    float: left;
    margin-left: 15px;
}
.annui{
    text-align: center;
    padding: 2% 0;
}
</style>